/* eslint-disable @typescript-eslint/no-unused-vars */
import { request } from '@umijs/max';

export const loadDataAPI = async (
  // 第一个参数 params 查询表单和 params 参数的结合
  // 第一个参数中一定会有 pageSize 和  current ，这两个参数是 antd 的规范
  params: any & {
    pageSize: number;
    current: number;
  },
  //@ts-ignore
  sort,
  //@ts-ignore
  filter,
) => {
  const { current, pageSize, ...others } = params;
  const res = await request('/admin/illnesses', {
    params: {
      ...others,
      page: params.current,
      per: params.pageSize,
    },
  });
  //console.log(res);

  return {
    data: res.data.list,
    // success 请返回 true，
    // 不然 table 会停止解析数据，即使有数据
    success: true,
    // 不传会使用 data 的长度，如果是分页一定要传
    total: res.data.total,
  };
};
/* add */
export const addOneAPI = (data: any) => {
  return request('/admin/illnesses', {
    method: 'POST',
    data,
  });
};

/* xiugai */
export const modifyByIdAPI = (id: any, data: any) => {
  return request('/admin/illnesses/' + id, {
    method: 'PATCH',
    data,
  });
};

/* huoxu */
export const loadOneByIdAPI = (id: string) => request('/admin/illnesses/' + id);

/* del */
export const deleteByIdAPI = (id: string) =>
  request('/admin/illnesses/' + id, {
    method: 'DELETE',
  });

/* dels */
export const deleteManyByIds = (ids: any) => {
  request('/admin/illnesses/remove_many', {
    params: {
      ids,
    },
    method: 'DELETE',
  });
};
/* 分类 */
export const loadAllIllnessesAPI = () =>
  request('/admin/illness_categories', {
    params: {
      per: 100,
    },
  });
